import java.util.HashMap;

import edu.pku.hawk.controller.util.Constants;
import edu.pku.hawk.controller.util.MConsumerQueue;
import edu.pku.hawk.controller.util.MProducerQueue;
import edu.pku.hawk.controller.util.MQManager;
import edu.pku.hawk.controller.util.ProcDes;
import edu.pku.hawk.controller.util.SerResource;
import edu.pku.hawk.controller.util.SerResourceList;

public class SendSample {

	public static void main(String[] args) {
		SendSample ss = new SendSample();
		ss.send();
	}

	private MQManager mgr;

	public SendSample() {

		try {
			mgr = new MQManager(Constants.MQServer_Name,
					Constants.MQServer_Password, Constants.MQServer_URL);
			mgr.createProducerQueue(Constants.Ctrl_Cloud_RscRequest_QueueName);
		} catch (Exception ex) {
			ex.printStackTrace();
		}

	}

	public void send() {

		HashMap<Integer, SerResource> map = new HashMap<Integer, SerResource>();

		SerResource sr = new SerResource();
		sr.setServiceName("服务1");
		sr.setCpu(0.2);
		sr.setDisk(0.2);
		sr.setMem(10);
		sr.setNet(15);
		sr.setServiceID(1);
		sr.setClientURI("192.168.0.2");

		map.put(1, sr);

		sr = new SerResource();
		sr.setServiceName("服务2");
		sr.setCpu(0.1);
		sr.setDisk(0.4);
		sr.setMem(20);
		sr.setNet(30);
		sr.setServiceID(2);
		sr.setClientURI("192.168.0.4");
		map.put(2, sr);

		SerResourceList srl = new SerResourceList(map);

		srl.setCjName("场景1");

		srl.setEnable(false);

		try {
			MProducerQueue queue = mgr
					.getProducerQueue(Constants.Ctrl_Cloud_RscRequest_QueueName);
			queue.send(srl);

			// MConsumerQueue q = mgr
			// .getConsumerQueue(Constants.Ctrl_Cloud_RscResponse_QueueName);
			// SerResourceList rsp = (SerResourceList) q.getObject();
			//
			// System.out.print(rsp.ResourceList.size());
			// System.out.println(rsp.ResourceList.get(0).getUri());

		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}

	public void send1() {

		ProcDes procDes = new ProcDes();
		procDes.isConbine = true;
		procDes.detectorTypes = new int[] { Constants.TYPE_INFRARED_SENSOR,
				Constants.TYPE_METAL_SENSOR, Constants.TYPE_PRESSURE_SENSOR };

		try {
			MProducerQueue queue = mgr
					.getProducerQueue(Constants.Ctrl_UI_Proc_QueueName);
			queue.send(procDes);
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}

}
